package com.agent.vpsserver.modules.server.service.impl;

import com.agent.vpsserver.common.dto.AdminAccountTokenDTO;
import com.agent.vpsserver.common.dto.AdminPageTokenRequestDTO;
import com.agent.vpsserver.common.dto.PageBean;
import com.agent.vpsserver.common.utils.mapping.BeansUtils;
import com.agent.vpsserver.modules.server.entity.pojo.ServerInfoDO;
import com.agent.vpsserver.modules.server.mapper.ServerInfoMapper;
import com.agent.vpsserver.modules.server.response.ServerInfoPageResponse;
import com.agent.vpsserver.modules.server.service.ServerInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务器信息(ServerInfo)表服务实现类
 *
 * @author guochao
 * @since 2024-03-12 23:50:18
 */
@Service
public class ServerInfoServiceImpl extends ServiceImpl<ServerInfoMapper, ServerInfoDO> implements ServerInfoService {

    @Override
    public PageBean<ServerInfoPageResponse> pageData(AdminPageTokenRequestDTO request) {
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<ServerInfoDO> serverInfos = baseMapper.selectList(null);
        List<ServerInfoPageResponse> responseList = BeansUtils.mapList(serverInfos, ServerInfoPageResponse.class);
        PageBean<ServerInfoPageResponse> pageBean = new PageBean<>();
        pageBean.setPageInfo(serverInfos);
        pageBean.setList(responseList);
        return pageBean;
    }

    @Override
    public List<ServerInfoPageResponse> listData(AdminAccountTokenDTO request) {
        List<ServerInfoDO> serverInfos = baseMapper.selectList(new LambdaQueryWrapper<ServerInfoDO>()
                .eq(ServerInfoDO::getStatus, 1));
        return BeansUtils.mapList(serverInfos, ServerInfoPageResponse.class);
    }

}
